//
//  RHStatusCell.swift
//  微博新浪
//
//  Created by hezerong on 16/6/13.
//  Copyright © 2016年 Rocky. All rights reserved.
//

import UIKit

class RHStatusCell: UITableViewCell {
    
    //viewmodel
    var statusViewModel:RHStatusViewModel?{
    
        didSet{
            
            pictureView.viewModel = statusViewModel
        
            originalView.statusViewModel = statusViewModel
            retweetedView.statusViewModel = statusViewModel
            toolBar.statusViewModel = statusViewModel
            
            //更新status
            pictureView.snp_updateConstraints { (make) -> Void in
                make.top.equalTo(originalView.snp_bottom).offset(12)
                make.left.equalTo(originalView).offset(12)
                make.size.equalTo((statusViewModel?.pictureViewSize)!)
            }

            
        
        }
    }

    //原创微博
    let originalView:RHOriginalView = RHOriginalView()
    //转发微博
    let retweetedView:RHRetweetedView = RHRetweetedView()
    //工具栏
    let toolBar:RHToolBar = RHToolBar()
    //图片视图
    let pictureView:RHPictureView = RHPictureView()
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setUPUi()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}

extension RHStatusCell{

    func setUPUi(){
    
       //添加子控件
        contentView.addSubview(originalView)
        contentView.addSubview(retweetedView)
        contentView.addSubview(toolBar)
        contentView.addSubview(pictureView)
        
        originalView.backgroundColor = UIColor.whiteColor()

        
        //布局
        originalView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentView)
            make.left.equalTo(contentView)
            make.right.equalTo(contentView)
            
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(originalView.snp_bottom).offset(12)
            make.left.equalTo(originalView).offset(12)
            make.right.equalTo(originalView).offset(-12)
            make.height.equalTo(0)
            
        }
        
        retweetedView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(originalView.snp_bottom)
            make.left.equalTo(originalView)
            make.right.equalTo(originalView)
//            make.height.equalTo(200)
        }
        
        contentView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(self)
            make.left.equalTo(self)
            make.right.equalTo(self)
            make.bottom.equalTo(retweetedView)
        }
    }
   
}